<template>
    <view class="deviceManagement-page">

        <view class="return" @click="goToMine"><</view>

        <p class="navigation">设备管理</p>

        <view class="message">
            <image src="../../../static/images/my/deviceManagement/mipmap-xxxhdpi/11.png"></image>
            <p>当前账号</p>
            <span>{{mobile}}</span>
        </view>

        <view class="quantity">
            <view class="present">
                <span>{{ deviceList.length }}</span><p>当前在线数量</p>
            </view>
            <view class="maximum">
                <span>10</span><p>最大同时在线数量</p>
            </view>
        </view>

        <view class="onLine">在线列表</view>
        <view class="segmentation"></view>
        <view class="list">
            <view class="model" v-for="(device, index) in deviceList" :key="index">{{ device.device_name }}</view>
        </view>

    </view>
</template>

<script setup>
    import { getDevice } from '@/api/user';
    import { info } from '@/api/login';
    import { ref, onMounted } from 'vue';

    const mobile = ref('未登录'); // 用户手机号
    const deviceList = ref([]); // 用于存储设备列表数据

    onMounted(() => {
        getInformation();
        onlineUnit();
    });

    // 获取设备列表
    const onlineUnit = async () => {
        try {
            const res = await getDevice();

            // console.log('接口返回的完整数据：', res);

            if (res.code == 1) {
                // 添加其他成功提示的逻辑
                console.log('成功获取设备列表');
                deviceList.value = res.data;
            } else {
                // 添加显示错误提示信息的逻辑
                console.error('获取设备列表失败：', res.msg);
            }
        } catch (error) {
            console.error('获取设备列表过程中出现错误：', error.message);
        }
    };

    // 获取用户信息
    const getInformation = async () => {
        try {
            const res = await info();

            // console.log('接口返回的完整数据：', res);

            if (res.code == 1) {
                // 添加其他成功提示的逻辑
				mobile.value = res.data.mobile;
                console.log('成功获取用户信息');
            } else {
                // 添加显示错误提示信息的逻辑
				mobile.value = ('未登录');
                console.error('获取用户信息失败：', res.msg);
            }
        } catch (error) {
			mobile.value = ('未登录');
            console.error('获取用户信息过程中出现错误：', error.message);
        }
    };


    // 返回上一页
    const goToMine = () => {
        uni.navigateBack({
            delta: 1,
            animationType: 'pop-out',
            animationDuration: 1000,
        })
    }

</script>

<style lang="scss" scoped>

   .deviceManagement-page {
        background-color: #F4F7FA;
        width: 100%;
        height: 100%;
        background-image: url('@/static/images/my/deviceManagement/mipmap-xxxhdpi/1.png');
        background-size: 100%;
        background-repeat: no-repeat;
        // background-color: #aaddfa;
    }

    // 返回
   .return {
        position: absolute;
        left: 30px;
        top: 40px;
        font-size: 30px;
        color: #ffffff;
        // font-weight: bold;
    }

   .navigation {
        // background-color: #fff123;
        text-align: center;
        padding: 50px 0 20px 0;
        color: #ffffff;
    }

   .message {
        width: 100%;
        height: 150px;
        display: flex;
        align-items: center;
        flex-direction: column;
        // background-color: #ffaaff;
    }

   .message image {
        border-radius: 50%;
        width: 70px;
        height: 70px;
    }

   .message p {
        font-size: 15px;
        color: #ffffff;
        margin-top: 10px;
        margin-bottom: 5px;
    }

   .message span {
        color: #ffffff;
    }

   .quantity {
        width: 90%;
        height: 80px;
        margin: 0 auto;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        // background-color: #aaffff;
        background: linear-gradient(to bottom, #EDF6FF, #FFFFFF);
    }

   .present {
        width: 50%;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        bottom: 0px;
        border-right: #EAEEF0 solid 1px;
        // background-color: #ffaaff;
    }

   .present span {
        color: #318BED;
        font-size: 25px;
    }

   .present p {
        font-size: 15px;
    }

   .maximum {
        width: 50%;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        border-left: #EAEEF0 solid 1px;
        // background-color: #55ff7f;
    }

   .maximum span {
        color: #318BED;
        font-size: 25px;
    }

   .maximum p {
        font-size: 15px;
    }

   .onLine {
        width: 90%;
        height: 60px;
        margin: 0 auto;
        margin-top: 20px;
        padding-left: 20px;
        display: flex;
        align-items: center;
        border-radius: 10px 10px 0 0;
        background-color: #ffffff;
    }

   .segmentation {
        width: 90%;
        height: 1px;
        margin: 0 auto;
        background: linear - gradient(to right, #EAEEF0 0%, #EAEEF0 6%, #318BED 6%, #318BED 15%, #EAEEF0 15%, #EAEEF0 100%);
    }

   .list {
        width: 90%;
        height: 420px;
        margin: 0 auto;
        // display: flex;
        // flex-wrap: wrap;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(7, 1fr);
        border-radius: 0px 0px 10px 10px;
        background-color: #fff;
    }

   .model {
        width: 160px;
        height: 40px;
        border-radius: 50px;
        background-color: #ffffff;
        border: #000000 solid 1px;
        font-size: 15px;
        margin-left: 10px;
        margin-top: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

</style>